'use strict';

const Controller = require('egg').Controller;

const rulesAddItem = {
  type: {
    type: 'string',
    required: true
  },
  title: {
    type: 'string',
    required: true
  },
}

class AddItem extends Controller {
  /**
   * 添加试题
   */
  async AddQuestion() {
    const {
      ctx,
      service,
      app
    } = this;
    const body = ctx.request.body;
    const info = app.validator.validate(rulesAddItem, body);
    let data = info
    if (!info) {
      data = await service.addItem.add(body);
    }
    ctx.body = {
      code: 0,
      message: 'success',
      data,
    }
  }
  /**
   * 查询所有列表
   */
  async FindAll() {
    const {
      ctx,
      service,
    } = this;
    const query = ctx.query;
    const data = await service.addItem.findAll(query);
    ctx.body = {
      code: 0,
      message: 'success',
      data
    }
  }
  /**
   * 删除
   */
  async DeleteId() {
    const {
      ctx,
      service
    } = this;
    const id = ctx.params.id;
    const data = await service.addItem.deleteId(id);
    ctx.body = {
      code: 0,
      messgae: 'success',
      data
    }
  }
}

module.exports = AddItem;